1. Field of the Invention
The Present Invention relates to optimization of an executable code in a programming language processor. More particularly, the Present Invention is related to an inlining technique.
2. Description of Related Art
Dynamic scripting languages such as PHP and more static programming languages such as Java(R) have conventionally been used for programming language processors or execution systems in the server environments. In recent years, in order to allow Java(R) class resources to be readily invoked from PHP and the like, a mechanism has been proposed, where the mechanism declares a class of static language platform from a program in a dynamic scripting language such as PHP to allow untyped accesses on a Java(R) virtual machine or a static language platform. (e.g., common language infrastructure (CLI)).
Particularly, known platforms that operate on Java(R) virtual machine include P8 and Quercus as PHP, JRuby as Ruby, Jython as Python, and Groovy.
Almost all the bytecodes generated by these scripting language processors form a subroutine threading style in order to process language constructs, which can contain complex semantics. A feature of a function or method which is invoked as a subroutine is sometimes referred to as a runtime helper function. Such a subroutine call can be optimized by inlining at least one function or method being invoked and combining the same with other inlined functions or methods.
The following is an example of such inlining. First, assume that the following bytecode has been generated:
 Obj f(Obj a, Obj b, Obj c){load aload binvoke add(Obj,Obj)load cinvoke sub(Obj,Obj) . . .invoke print(Obj) . . .
When the above code is expressed as pseudo-source code for ease of understanding (the same applies below), the following is derived.
 Obj f(Obj a, Obj b, Obj c){print(sub(add(a,b), c)) . . .
Assume that the above code of add(Obj,Obj) which is invoked is as follows.
 Obj add(Obj x, Obj y){ if (x instanceof Int && y instanceof Int){  return new Int(x.getInt( ) + y.getInt( )); } else if (x instanceof Dbl . . . ){  . . . } else if ( . . . ){. . .
Also, assume that the above code of sub(Obj,Obj) being invoked is as follows.
 Obj sub(Obj x, Obj y){ if (x instanceof Int && y instanceof Int){  return new Int(x.getInt( ) − y.getInt( )); }else if (x instanceof Dbl . . . ){  . . . }else if ( . . . ){. . .
If add(Obj x, Obj y) and sub(Obj x, Obj y) are inlined into the original bytecode, evaluation of the common sub-expressions can be performed at once, and generation of intermediate data can be eliminated, leading to increased speed of code execution.
The code of such a subroutine, however, is too large in size to be inlined using a conventional scripting language compiler. Therefore, the size of the inlined code will become too large, and optimization can be hindered within a realistic time frame.
Japanese Unexamined Patent Publication No. 2007-109044 discloses a code conversion program that includes: a dedicated invoked program generation unit which detects an invoked program from a program group, an argument for differentiating processes of the invoked program, and the content of the argument, and generates a program for only executing a process that corresponds to the content of the argument within the processes of the invoked program; a call site detection unit which detects a call site that invokes the invoked program from the program group; and an invoking program rewriting unit which rewrites the call site to invoke the dedicated invoked program generated by the dedicated invoked program generation unit. This technique, however, does not suggest an application for code inlining. Furthermore, in cases where the contents of a plurality of arguments potentially vary, the number of dedicated invoked programs will become too many that corresponds with the number of combinations. It is impractical to do the same at runtime.
Suganama, et al., “An Empirical Study of Method In-lining for a Java Just-in-Time Compiler,” Proceedings of the 2nd JVM Symposium, p. 91-104, August, 2002, discloses a technique that inlines a hot path in a large method body. Suganuma's technique, however, cannot be applied to cases where a runtime helper function is invoked from a large number of call sites in different contexts, because the hot path cannot be determined.
Whaley, “Dynamic Optimization through the use of Automatic Runtime Specialization”, thesis for MASSACHUSETTS INSTITUTE OF TECHNOLOGY, Can 1999, particularly in Chapter 3.4.16, discusses about predicting the benefit obtained from a code which is specialized on the basis of the parameter type.
Arnold, et al. “A Comparative Study of Static and Profile-Based Heuristics for Inlining”, ACM SIGPLAN Notices archive, Volume 35, Issue 7, pp. 52-64, July 2000, discusses profile-based heuristics for inlining.